import colors from 'colors/safe';
import { Dayjs } from 'dayjs';
import _ from 'lodash';

export default class Printer {
  // eslint-disable-next-line no-console
  static log = console.log;

  static warn = (message: string, ...args: any[]) => {
    Printer.log(
      colors.bgYellow('[WARN]'),
      colors.yellow(message),
      ...args,
    );
  };

  static error = (message: string, ...args: any[]) => {
    Printer.log(
      colors.bgRed('[ERROR]'),
      colors.red(message),
      ...args,
    );
  };

  static describe = (label: string, description: string, context: any) => {
    Printer.log(
      colors.bgWhite(label),
      description,
      _.isString(context) ? colors.green(context) : context,
    );
  };

  static getDurationAsSecond = (startedAt: Dayjs, endedAt: Dayjs) => {
    const durationMillisecond = endedAt.diff(startedAt);
    const durationSecond = endedAt.diff(startedAt, 'second');
    return `${durationSecond}.${durationMillisecond % 1000}`;
  };
}
